package com.dgut.controller;

import com.dgut.entity.PurchaseOrder;
import com.dgut.result.PageResult;
import com.dgut.result.Result;
import com.dgut.service.PurchaseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "进货单管理")
@RequestMapping("/purchaseOrder")
public class PurchaseOrderController {
    @Autowired
    private PurchaseOrderService purchaseOrderService;

    @ApiOperation("新增进货单")
    @PostMapping
    public Result save(@RequestBody PurchaseOrder purchaseOrder) {
        log.info("新增进货单: 参数purchaseOrder:{}", purchaseOrder);
        purchaseOrderService.save(purchaseOrder);
        return Result.success();
    }

    @ApiOperation("分页查询进货单")
    @GetMapping
    public Result pageQuery(Integer currentPage, Integer pageSize) {
        log.info("分页查询进货单: 参数currentPage:{}, pageSize:{}", currentPage, pageSize);
        PageResult pg = purchaseOrderService.pageQuery(currentPage, pageSize);
        return Result.success(pg);
    }

    @PutMapping("/confirm/{id}")
    @ApiOperation("确认进货单完成")
    public Result confirm(@PathVariable Long id) {
        log.info("确认进货单: 参数id:{}", id);
        purchaseOrderService.confirm(id);
        return Result.success();
    }
}
